package com.xbh.dms.controller;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;

import com.jfinal.core.paragetter.Para;
import com.jfinal.json.FastJson;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.plugin.redis.Redis;
import com.jfinal.upload.UploadFile;
import com.xbh.common.model.Student;
import com.xbh.dms.service.StuService;
import com.xbh.validator.MyValidator;


import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;


@Path("/stu")
public class StuController extends Controller {

    @Inject
    StuService stuService;

    @Before(Tx.class)
    public void index() throws Exception {
//        getFile("aaa");
//        String stuId = get("stuId");
//        if(Redis.use().exists(stuId)){
//            System.out.println("从Redis中拿到的信息-->");
//            renderText(Redis.use("stu").get(stuId));
//            return;
//        }
//        String stu = stuService.getOne(stuId);
//        renderText(stu);

//        List<Student> stuList = stuService.getAll();
//        Student student = getModel(Student.class, "");
//        Student student = FastJson.getJson().parse(getRawData(), Student.class);

//        System.out.println(student);
//        boolean flag = stuService.addOne(student);
//        boolean flag = stuService.updateOne(student);
//        Page<Student> page = stuService.paginate(1, 5, 5);
//        boolean falg = stuService.deleteById(1);
//        System.out.println(page.toString());
//        if(falg){
//            renderText("删除成功!!!");
//            return;
//        }

//        List<Long> list = stuService.queryInteger();
//        list.forEach(integer -> System.out.println(integer + "->"));

//        List<Student> list = stuService.enjoyDemo(2, 1708054106);
//        if(list.size() >0){
//            renderText(FastJson.getJson().toJson(list));
//            return;
//        }
//        renderText("删除失败!!!");
//        Student s = getModel(Student.class, "");
//        System.out.println(s);
//        keepModel(Student.class);
//        System.out.println("=====" + s);
//        List<Student> list = new ArrayList<>();
        /*for (int i = 0; i < 3; i++) {
            Student student = new Student();
            student.setStuNum(i);
            student.setStuName(i + "");
            list.add(student);
        }*/
        /*Student student0 = new Student();
        student0.setStuId(Long.valueOf(14 + ""));
        student0.setStuNum(0);
        student0.setStuName("1");
        Student student1 = new Student();
        student1.setStuId(Long.valueOf(15 + ""));
        student1.setStuNum(1);
        student1.setStuName("2");
        Student student2 = new Student();
        student2.setStuId(Long.valueOf(16 + ""));
        student2.setStuNum(2);
        student2.setStuName("3");
        list.add(student0);
        list.add(student1);
        list.add(student2);*/
        /*List<Record> records = new ArrayList<>();
        Record r0 = new Record().set("stu_id", 14).set("stu_num", 0).set("stu_name", "1");
        Record r1 = new Record().set("stu_id", 15).set("stu_num", 1).set("stu_name", "2");
        Record r2 = new Record().set("stu_id", 16).set("stu_num", 2).set("stu_name", "3");*/
//        String s = stuService.beachTest(list);
        Student student = new Student();
        student.setStuName("00");
        student.setStuNum(1999122100);
        Record record = stuService.addOne0(student);
        renderJson(record);
//        renderText("-----------------------");
    }

    @Before(MyValidator.class)
    public void one() {

        renderJson("---------");
    }
}
